package com.shenzw.mybatisdemo.service.impl;

import com.shenzw.mybatisdemo.controller.response.DeptResponseMore;
import com.shenzw.mybatisdemo.controller.response.EmployeeResponseOne;
import com.shenzw.mybatisdemo.domain.Dept;
import com.shenzw.mybatisdemo.repository.DeptRepository;
import com.shenzw.mybatisdemo.service.DeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shenzw
 * @date 2023/11/30
 */
@Service(value = "deptServiceImpl")
@RequiredArgsConstructor
public class DeptServiceImpl implements DeptService {

    private final DeptRepository deptRepository;

    @Override
    public List<DeptResponseMore> getDeptInfo(Integer deptId) {
        return deptRepository.getDeptInfo(deptId);
    }

    @Override
    public List<EmployeeResponseOne> getEmploy(Integer id) {
        return deptRepository.getEmploy(id);
    }

    @Override
    public List<Dept> selectDeptByName(String name) {
        return deptRepository.selectDeptByName2(name);
    }

    @Override
    public Dept selectDeptById(Integer id) {
        return deptRepository.selectDeptById(id).orElseGet(Dept::new);
    }
}
